﻿using System;
using NUnit.Framework;
using System.Linq;

namespace Mrb.Utils.Tests
{
    [TestFixture]
    public class TestConfiguration
    {
        [Test]
        public void TestLoadJsonFile()
        {
            var properties = Configuration.LoadJsonPropertiesFromFile(@".\Config\Default\config.json");
            Assert.Greater(properties.Count(), 2);
            Assert.AreEqual("simplevalue", properties["simplekey"]);
            var array = properties["arraykey"];
            Console.WriteLine(array);
        }

        [Test]
        public void TestLoadConfiguration()
        {
            var config = Configuration.CreateAndLoad();
            Assert.AreEqual("simplevalue", config["simplekey"]);

            var array = config.ParseJsonArray<string>("arraykey");
            Assert.AreEqual(2, array.Count());
            Assert.AreEqual("arrayvalue1", array.ElementAt(0));
            Assert.AreEqual("arrayvalue2", array.ElementAt(1));

            var configObject = config.ParseJsonObject<TestConfigObject>("objectkey");
            Assert.AreEqual("namevalue", configObject.Name);
            Assert.AreEqual(1.2, configObject.DoubleValue);

            var configArrayObject = config.ParseJsonArray<TestConfigObject>("objectarraykey");
            Assert.AreEqual(2, configArrayObject.Count());
            Assert.AreEqual("name1", configArrayObject.ElementAt(0).Name);
            Assert.AreEqual(1.3, configArrayObject.ElementAt(0).DoubleValue);
            Assert.AreEqual("name2", configArrayObject.ElementAt(1).Name);
            Assert.AreEqual(1.4, configArrayObject.ElementAt(1).DoubleValue);
        }
    }

    public class TestConfigObject
    {
        public string Name { get; set; }
        public double DoubleValue { get; set; }
    }
}